// Source : https://leetcode.com/problems/reverse-integer/
// Author : simba
// Date   : 2016-06-20

package main

import (
	"fmt"
	"math"
)

func reverse(x int) int {
	res := 0
	for x != 0 {
		res = res*10 + x%10
		x /= 10
		if (res > math.MaxInt32) || (res < math.MinInt32) {
			return 0
		}
	}

	return res
}

func main() {
	//固定测试用例
	s1 := 1
	a1 := reverse(s1)
	fmt.Println("数", s1)
	fmt.Println("输出答案", a1)
	fmt.Println("正确答案 1")

	s2 := 13579
	a2 := reverse(s2)
	fmt.Println("数", s2)
	fmt.Println("输出答案", a2)
	fmt.Println("正确答案 97531")

	s3 := 0
	a3 := reverse(s3)
	fmt.Println("数", s3)
	fmt.Println("输出答案", a3)
	fmt.Println("正确答案 0")

	s4 := -13579
	a4 := reverse(s4)
	fmt.Println("数", s4)
	fmt.Println("输出答案", a4)
	fmt.Println("正确答案 -97531")

	s5 := -1
	a5 := reverse(s5)
	fmt.Println("数", s5)
	fmt.Println("输出答案", a5)
	fmt.Println("正确答案 -1")

	//原数不超界，逆序超界
	s6 := 1534236469
	a6 := reverse(s6)
	fmt.Println("数", s6)
	fmt.Println("输出答案", a6)
	fmt.Println("正确答案 0")
}
